package 力扣.动态规划.最长公共子序列;

public class MaxConSon {

    public int longestCommonSubsequence(String text1, String text2) {
        int len1=text1.length();
        int len2=text2.length();
        int[][] a=new int[len1+1][len2+1];
        for (int i = 0; i <len1 ; i++) {
            for (int j = 0; j < len2; j++) {
                   if (text1.charAt(i) == 0 || text2.charAt(j) == 0){
                       return 0;
                   }
                   if (text1.charAt(i) == text2.charAt(j)){
                       a[i+1][j+1]=a[i][j]+1;
                  }else {
                       a[i+1][j+1]=Math.max(a[i+1][j],a[i][j+1]);
                   }
            }
        }
        return a[len1][len2];
    }

    public static void main(String[] args) {
        String text1="abcdewqqba";
        String text2="abccdewaabb";
        int i = new MaxConSon().longestCommonSubsequence(text1, text2);
        System.out.println(i);
    }
}

